package com.xsmart.payment.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface PaymentConfigruationDao {
    /**
     * 按条件查找数据
     * @param page
     * @param goodsTypeMap
     * @return
     */
    @Select("<script>" +
            "select * from payment where 1=1" +
            "<if test=\"pay_code != null and pay_code != ''\">" +
            "and pay_code=#{pay_code}" +
            "</if>" +
            "<if test=\"enabled!=null\">" +
            "and enabled=#{enabled}" +
            "</if>" +
            "</script>")
    List<Map<String, Object>> queryPaymentConfigruation(Pagination page, Map goodsTypeMap);

    /**
     * 查找全部数据
     * @return
     */
    @Select("select pay_id as value, pay_code as label from payment ")
    List<Map<String,Object>> queryAllPaymentConfigruation();

    /**
     * 新增
     * @param paymentConfigruationMap
     * @return
     */
    @Insert("insert into payment" +
            "(pay_code," +
            "pay_name," +
            "pay_fee," +
            "pay_desc," +
            "pay_order," +
            "pay_config," +
            "enabled," +
            "is_cod," +
            "is_online )" +
            "values (" +
            "#{paymentConfigruationMap.pay_code}," +
            "#{paymentConfigruationMap.pay_name}," +
            "#{paymentConfigruationMap.pay_fee}," +
            "#{paymentConfigruationMap.pay_desc}," +
            "#{paymentConfigruationMap.pay_order}," +
            "#{paymentConfigruationMap.pay_config}," +
            "#{paymentConfigruationMap.enabled}," +
            "#{paymentConfigruationMap.is_cod}," +
            "#{paymentConfigruationMap.is_online})")
    int addPaymentConfigruation(@Param("paymentConfigruationMap")Map paymentConfigruationMap);

    /**
     * 更新
     * @param paymentConfigruationMap
     * @return
     */
    @Insert("update payment " +
            "set " +
            "pay_code = #{paymentConfigruationMap.pay_code}," +
            "pay_name = #{paymentConfigruationMap.pay_name}," +
            "pay_fee = #{paymentConfigruationMap.pay_fee}," +
            "pay_desc = #{paymentConfigruationMap.pay_desc}," +
            "pay_order = #{paymentConfigruationMap.pay_order}," +
            "pay_config = #{paymentConfigruationMap.pay_config}," +
            "enabled = #{paymentConfigruationMap.enabled}," +
            "is_cod = #{paymentConfigruationMap.is_cod}," +
            "is_online = #{paymentConfigruationMap.is_online} " +
            "where pay_id = #{paymentConfigruationMap.pay_id}")
    int modPaymentConfigruation(@Param("paymentConfigruationMap")Map paymentConfigruationMap);

    /**
     * 删除
     * @param pay_id
     * @return
     */
    @Delete("delete from payment where pay_id = #{pay_id}")
    int delPaymentConfigruation(Integer pay_id);
}
